import Taro, { Component } from '@tarojs/taro';
import { View, Text ,Image,Label } from '@doctorwork/components';
import { connect } from '@tarojs/redux';
import Navigate from '../../components/Navigate/index';
import { rewriteAddMTA } from '../../model/utils/rewrite';
import './index.styl';
import Empty from '../../components/Empty';

@connect(({ tipDetail , index}) => ({
    ...tipDetail, ...index
}))
@rewriteAddMTA
export default class tipDetail extends Component {
    config = {
        navigationBarTitleText: 'Tips详情',
        'navigationBarBackgroundColor': '#00c365',
        'navigationBarTextStyle': 'white'
    };
    
    componentDidMount(){
        const { id } = this.$router.params;
        this.props.dispatch({
            type : 'tipDetail/init',
            payload: {
                id
            }
        });
    }
    componentDidShow() {
        const { id } = this.$router.params;
        this.props.dispatch({
            type : 'tipDetail/init',
            payload: {id}
        });
        // 判断是否可见
        const {showTips} = this.props;
        if(!showTips){
            wx.switchTab({
                url: '/pages/index/index',
            });
        }
    }

    jumpDetail(id){
        this.props.dispatch({
            type : '$router/forward',
            payload : {
                url : `/pages/detail/index?id=${id}`,
            }
        });
    }


    render() {
        const {detail} = this.props;
        return (
            <View className='container'>
                <Navigate
                    title='tips详情'
                    color='white'
                    backgroundColor='#00c365'
                    backTextColor='white'
                />
                {
                    detail && <View>
                        <View className='title'>{detail.title}</View>
                        <Image src={detail.images} className='image'></Image>
                        <View className='content'>{detail.content}</View>
                    </View>
                }
                
            </View>

        );
    }
}
